﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Test Post</title>
    
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<div style="padding: 10px;border: 3px solid #62a805;border-radius: 5px;">
<button  onclick="login()">测试登录</button>
<button  onclick="login2()">测试登录2</button>
<button  onclick="GetTokenInfo()">获取登录人信息</button>

<button  onclick="CreateData()">创建一条数据</button>
<button  onclick="FindOnd()">读取一条数据</button>
<button  onclick="FindDatas()">查找一批数据</button>
<button  onclick="UpdateData()">修改数据</button>
<button  onclick="DeleteData()">删除数据</button>
</div>

<div style="border: 1px solid #62a805;border-radius: 5px;margin-top:10px;">
<div style="background-color:#62a805;padding:3px;color:#fff;">Function result:</div>
<div id="result" style="padding:10px;border-top:1px solid #62a805;"></div>
</div>
   <script>
      var apiurl="http://localhost:1008";
	  apiurl="http://www.bestqueen.cn";
	  var AccessKey="fjy_0000";
	  var token="";
	  
	  function setCookie(name,value)
		{
		var Days = 30;
		var exp = new Date();
		exp.setTime(exp.getTime() + Days*24*60*60*1000);
		document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
		}
	  
	  setCookie("token",token);
	  
	
	  
	  
	  
	  function login(){	 
       
        var JsonData = {};
        JsonData.accout = "zhangouchuanzi";
        JsonData.password = "zocz0109"; 
		JsonData.APIsecretkey=AccessKey;
        $.ajax({
           type: "POST",
           contentType: "application/json;charset=UTF-8",
           url: apiurl+"/login",
           data: JSON.stringify(JsonData),
           success: function (result) {
		       token=result.token;
               console.log("ajax_post", result);			    
			   setCookie("token",result.token);
			    $("#result").html(JSON.stringify(result));
           }
       });
    }
	 
function login2(){	 
       
        var JsonData = {};
        JsonData.accout = "zhangouchuanzi";
        JsonData.password = "zocz0109"; 
		JsonData.APIsecretkey=AccessKey;
        $.post(apiurl+"/login",JsonData,function(result){
		$("#result").html(JSON.stringify(result));
		});
    }
	
	  /*
	  var JsonData = {};
        JsonData.ActtionType = "create";//四种类型：find、findone、create、delete、update
        JsonData.CollectionName = "Project";//必填，对应的Collection名称
        JsonData.Filters = { _id: "590a9c2f29ace0ab2fe6f3a8"};	//find、findone、update、delete必填	，后台默认{}
		JsonData.SearchItems = { _id: 0, password: 0 };//find、findone 时候选填，后台默认{}
		JsonData.SortItems = { "code": 1 };//find 时候选填,可不传，后台默认{"CreateTime":-1}
		JsonData.PageSize = 10;//find 时候选填，后台默认10
		JsonData.PageIndex = 1;//find 时候必填，后台默认1
		JsonData.DocumentModel={"Name":"text","Status":"acttive"};//create、update 时候必填
		JsonData.APIsecretkey="fjy_0000";
	  */
	  
	  function CreateData(){	 
       
        var JsonData = {};
        JsonData.ActtionType = "create";//四种类型：find、findone、create、delete、update
        JsonData.CollectionName = "User2";//必填，对应的Collection名称
		JsonData.DocumentModel={   
			"code" : "zhangouchuanzi", 
			"name" : "张欧川子", 
			"address" : "山东省肥城市", 
			"telphone" : "15194389479", 
			"birthday" : "", 
			"identityID" : "", 
			"weixin" : "chuan00135", 
			"password" : "zocz0109", 
			"photo" : "zhangouchuangzi.jpg"
		};//create、update 时候必填
		JsonData.APIsecretkey=AccessKey;
		JsonData.token=token;
		
        $.ajax({
		   headers:{'token':token},
           type: "POST",
           contentType: "application/json;charset=UTF-8",
           url: apiurl+"/ProcessData",
           data: JSON.stringify(JsonData),
           success: function (result) {
               console.log("ajax_post", result);
               $("#result").html(JSON.stringify(result));	
			   
           }
       });
    }
	
	
	
	function FindOnd(){	 
       
        var JsonData = {};
        JsonData.ActtionType = "findone";//四种类型：find、findone、create、delete、update
        JsonData.CollectionName = "User";//必填，对应的Collection名称
        JsonData.Filters = { "_id" : "60bebba0da8c11e99f599d0f3207b9f5"};	//find、findone、update、delete必填	
		JsonData.SearchItems = { };//find、findone 时候选填，后台默认{}		
		JsonData.APIsecretkey=AccessKey;
		JsonData.token=token;
		
        $.ajax({
		   headers:{'token':token},
           type: "POST",
           contentType: "application/json;charset=UTF-8",
           url: apiurl+"/ProcessData",
           data: JSON.stringify(JsonData),
           success: function (result) {
               console.log("ajax_post", result);
                $("#result").html(JSON.stringify(result));			   
           }
       });
    }
	
	function FindDatas(){	 
       
        var JsonData = {};
        JsonData.ActtionType = "find";//四种类型：find、findone、create、delete、update
        JsonData.CollectionName = "User";//必填，对应的Collection名称
        JsonData.Filters = { code:{$in:['yeyu','zhangouchuanzi','zhangting']}};	//find、findone、update、delete必填	
		JsonData.SearchItems = { code: 1, name: 1,address:1 };//find、findone 时候选填，后台默认{}
		JsonData.SortItems = { "name": 1 };//find 时候选填，后台默认{_id:-1}
		JsonData.PageSize = 10;//find 时候选填，后台默认10
		JsonData.PageIndex = 1;//find 时候必填，后台默认1
		JsonData.APIsecretkey=AccessKey;
		JsonData.token=token;
		
        $.ajax({
		   headers:{'token':token},
           type: "POST",
           contentType: "application/json;charset=UTF-8",
           url: apiurl+"/ProcessData",
           data: JSON.stringify(JsonData),
           success: function (result) {
               console.log("ajax_post", result);	
                $("#result").html(JSON.stringify(result));			   
           }
       });
    }
	
	function UpdateData(){	 
       
        var JsonData = {};
        JsonData.ActtionType = "update";//四种类型：find、findone、create、delete、update
        JsonData.CollectionName = "User";//必填，对应的Collection名称
        JsonData.Filters = { "code" : "zhangouchuanzi"};	//find、findone、update、delete必填			
		JsonData.DocumentModel={"Remark":"难忘的女孩子"};//create、update 时候必填
		JsonData.APIsecretkey=AccessKey;
		JsonData.token=token;
		
        $.ajax({
		   headers:{'token':token},
           type: "POST",
           contentType: "application/json;charset=UTF-8",
           url: apiurl+"/ProcessData",
           data: JSON.stringify(JsonData),
           success: function (result) {
               console.log("ajax_post", result);	
                $("#result").html(JSON.stringify(result));			   
           }
       });
    }
	
	function DeleteData(){	 
       
        var JsonData = {};
        JsonData.ActtionType = "delete";//四种类型：find、findone、create、delete、update
        JsonData.CollectionName = "logs";//必填，对应的Collection名称
        JsonData.Filters = { _id: "dcbc7850da8711e99f599d0f3207b9f5"};	//find、findone、update、delete必填			
		JsonData.APIsecretkey=AccessKey;
		JsonData.token=token;
		
        $.ajax({
		   headers:{'token':token},
           type: "POST",
           contentType: "application/json;charset=UTF-8",
           url: apiurl+"/ProcessData",
           data: JSON.stringify(JsonData),
           success: function (result) {
               console.log("ajax_post", result);	
                $("#result").html(JSON.stringify(result));			   
           }
       });
    }
	
	
	function GetTokenInfo(){	 
       
        var JsonData = {};        	
		JsonData.APIsecretkey=AccessKey;
		JsonData.token=token;
		
        $.ajax({
		   headers:{'token':token},
           type: "POST",
           contentType: "application/json;charset=UTF-8",
           url: apiurl+"/getUserByToken",
           data: JSON.stringify(JsonData),
           success: function (result) {
               console.log("ajax_post", result);	
                $("#result").html(JSON.stringify(result));			   
           }
       });
    }
   </script>
</body>
</html>